﻿<template>
  <s-layout :title="product.name || '产品详情'">
    <view class="detail-container">
      <scroll-view scroll-y class="content-scroll">
        <!-- 商品主图 -->
        <image class="product-main-image" :src="product.image" mode="widthFix" />

        <!-- 商品信息 -->
        <view class="product-info-card">
          <view class="product-name">{{ product.name }}</view>
          <view class="product-desc">{{ product.description }}</view>
          <view class="product-price">¥{{ currentPrice }}</view>
        </view>

        <!-- 规格选择 -->
        <view class="spec-card" v-if="product.specs && product.specs.length > 0">
          <view class="spec-group" v-for="spec in product.specs" :key="spec.id || spec.name">
            <view class="spec-group-header">
              <view class="spec-group-name">
                {{ spec.name }}
                <text v-if="spec.mandatory === 1" class="spec-required">*必选</text>
              </view>
            </view>
            <view class="spec-options">
              <button
                  class="spec-option"
                  v-for="option in spec.options"
                  :key="option.id || option.code || option.name"
                  :class="{
                  active: isOptionSelected(spec, option),
                  disabled: isOptionDisabled(spec, option)
                }"
                  :disabled="isOptionDisabled(spec, option)"
                  @click="selectSpec(spec, option)"
              >
                <view class="option-name">{{ option.name }}</view>
                <view class="option-price" v-if="option.price && option.price > 0">
                  +¥{{ option.price }}
                </view>
              </button>
            </view>
          </view>
        </view>

        <!-- 加料选择（奈雪） -->
        <view class="spec-card" v-if="product.accessories && product.accessories.length > 0">
          <view class="spec-group">
            <view class="spec-group-name">加料选项</view>
            <view class="spec-options">
              <button
                  class="spec-option"
                  v-for="accessory in product.accessories"
                  :key="accessory.code"
                  :class="{ active: selectedAccessories.includes(accessory.code) }"
                  @click="toggleAccessory(accessory)"
              >
                <view class="option-name">{{ accessory.name }}</view>
                <view class="option-price">+¥{{ accessory.price }}</view>
              </button>
            </view>
          </view>
        </view>

        <!-- 套餐包含商品（麦当劳/星巴克） -->
        <view class="included-products" v-if="product.requiredProducts && product.requiredProducts.length > 0">
          <view class="section-title">套餐包含</view>
          <view class="product-item" v-for="(item, index) in product.requiredProducts" :key="index">
            <image class="product-item-img" :src="item.img || item.product_img" mode="aspectFill" />
            <view class="product-item-info">
              <view class="product-item-name">{{ item.name || item.product_name }}</view>
              <view class="product-item-amount">x{{ item.amount || 1 }}</view>
            </view>
          </view>
        </view>
      </scroll-view>

      <!-- 底部操作栏 -->
      <view class="bottom-bar">
        <view class="price-section">
          <text>¥</text>
          <text class="price-value">{{ currentPrice }}</text>
        </view>
        <button class="add-to-cart-btn" @click="addToCart">加入购物车</button>
      </view>
    </view>
  </s-layout>
</template>

<script setup>
import { ref, reactive, computed, watch } from 'vue';
import sheep from '@/sheep';
import { onLoad } from '@dcloudio/uni-app';

// ==================== 常量定义 ====================
const BRAND_TYPES = {
  HEYTEA: 'HEYTEA',      // 喜茶
  NAIXUE: 'NAIXUE',      // 奈雪
  STARBUCKS: 'STARBUCKS', // 星巴克
  LUCKIN: 'LUCKIN',      // 瑞幸
  CUDI: 'CUDI',          // 库迪
  MCDONALD: 'MCDONALD',  // 麦当劳
  GENERIC: 'GENERIC'     // 通用
};

// 需要 SKU 匹配验证的品牌
const SKU_VALIDATION_BRANDS = [BRAND_TYPES.CUDI, BRAND_TYPES.NAIXUE, BRAND_TYPES.LUCKIN];

// ==================== 状态定义 ====================
const cateringStore = sheep.$store('catering');

const product = reactive({
  id: 0,
  name: '',
  image: '',
  description: '',
  basePrice: 0,
  specs: [],
  accessories: [], // 加料（奈雪）
  requiredProducts: [], // 套餐包含商品（麦当劳/星巴克）
  skuList: [], // SKU列表（奈雪/瑞幸/库迪）
  brandType: '', // 品牌类型，用于判断数据结构
});

const selectedSpecs = reactive({});
const selectedAccessories = ref([]); // 选中的加料

// ==================== 工具函数 ====================
// 获取规格的唯一标识
const getSpecKey = (spec) => spec.id || spec.name;

// 获取选项的唯一标识
const getOptionKey = (option) => option.id || option.code || option.name;

// 查找规格组
const findSpec = (specKey) => product.specs.find(s => getSpecKey(s) === specKey);

// 查找规格选项
const findOption = (spec, optionKey) => {
  if (!spec || !spec.options) return null;
  return spec.options.find(opt => getOptionKey(opt) === optionKey);
};

// 安全的数字转换
const safeParseFloat = (value, defaultValue = 0) => {
  const num = parseFloat(value);
  return isNaN(num) ? defaultValue : num;
};

onLoad(async (options) => {
  const passedProductId = options.productId || options.id;
  const passedShopId = options.shopId;

  if (!passedProductId) {
    uni.showToast({ title: '缺少商品信息', icon: 'error' });
    setTimeout(() => sheep.$router.back(), 1500);
    return;
  }

  const store = cateringStore.storeInfo;
  const shopId = passedShopId || (store && (store.shopId || store.id));
  if (!shopId) {
    uni.showToast({ title: '请先选择门店', icon: 'error' });
    setTimeout(() => sheep.$router.back(), 1500);
    return;
  }

  console.log('goodsDetail params =>', { productId: passedProductId, shopId });

  uni.showLoading({ title: '加载中...' });
  try {
    const res = await sheep.$api.catering.getProductDetail(passedProductId, shopId);
    uni.hideLoading();

    if ((res.code === 0 || res.code === 200) && res.data) {
      parseProductData(res.data, options);
    } else {
      uni.showToast({ title: '加载商品失败', icon: 'none' });
      setTimeout(() => sheep.$router.back(), 1500);
    }
  } catch (error) {
    uni.hideLoading();
    console.error('加载商品详情失败:', error);
    uni.showToast({ title: '加载商品失败', icon: 'error' });
    setTimeout(() => sheep.$router.back(), 1500);
  }
});

// ==================== 数据解析 ====================
// 解析不同餐厅的商品数据
function parseProductData(apiData, options) {
  // 基础信息解析
  product.id = apiData.product_id || apiData.productId || apiData.id || options.productId;
  product.name = apiData.product_name || apiData.productName || apiData.title || options.name || '';
  product.image = apiData.product_img || apiData.productImg || apiData.litimgUrl || apiData.imageUrl || '';
  product.description = apiData.product_description || apiData.productDescription || '';

  // 价格解析（不同品牌价格字段位置不同）
  // 优先级：salePrice > product_price > firstSku.salePrice > lowestPrice/100
  let basePrice = 0;
  if (apiData.salePrice != null && apiData.salePrice > 0) {
    basePrice = apiData.salePrice;
  } else if (apiData.product_price != null && apiData.product_price > 0) {
    basePrice = apiData.product_price;
  } else if (apiData.firstSku?.salePrice != null && apiData.firstSku.salePrice > 0) {
    basePrice = apiData.firstSku.salePrice; // 库迪特有
  } else if (apiData.lowestPrice != null && apiData.lowestPrice > 0) {
    basePrice = apiData.lowestPrice / 100; // 库迪：单位是分
  }
  product.basePrice = safeParseFloat(basePrice);

  const details = apiData.details || apiData;
  product.brandType = detectBrandType(details);

  console.log('【商品解析】品牌类型:', product.brandType, '基础价格:', product.basePrice);
  console.log('【价格数据】salePrice:', apiData.salePrice, 'product_price:', apiData.product_price,
      'firstSku.salePrice:', apiData.firstSku?.salePrice, 'lowestPrice:', apiData.lowestPrice);

  // 品牌解析映射表
  const parserMap = {
    [BRAND_TYPES.HEYTEA]: parseHeyteaSpecs,
    [BRAND_TYPES.NAIXUE]: parseNaixueSpecs,
    [BRAND_TYPES.STARBUCKS]: parseStarbucksSpecs,
    [BRAND_TYPES.LUCKIN]: parseLuckinSpecs,
    [BRAND_TYPES.CUDI]: parseCudiSpecs,
    [BRAND_TYPES.MCDONALD]: parseMcdonaldSpecs,
    [BRAND_TYPES.GENERIC]: parseGenericSpecs
  };

  // 执行对应的解析函数
  const parser = parserMap[product.brandType] || parseGenericSpecs;
  parser(details);

  // 初始化默认选中
  initializeDefaultSelection();
}

// 检测品牌类型
function detectBrandType(details) {
  // 品牌特征检测规则（按优先级顺序）
  const detectionRules = [
    {
      type: BRAND_TYPES.HEYTEA,
      check: () => details.specifications?.[0]?.values?.[0]?.exclusives !== undefined
    },
    {
      type: BRAND_TYPES.LUCKIN,
      check: () => details.specifications?.[0]?.ingredients !== undefined
    },
    {
      type: BRAND_TYPES.NAIXUE,
      check: () => details.spu_specs && details.accessories
    },
    {
      type: BRAND_TYPES.STARBUCKS,
      check: () => details.optional?.[0]?.sku_infos
    },
    {
      type: BRAND_TYPES.CUDI,
      check: () => details.specItems && details.skuCombinList
    },
    {
      type: BRAND_TYPES.MCDONALD,
      check: () => Array.isArray(details.required) && details.optional
    }
  ];

  for (const rule of detectionRules) {
    if (rule.check()) {
      return rule.type;
    }
  }

  return BRAND_TYPES.GENERIC;
}

// 解析喜茶规格
function parseHeyteaSpecs(details) {
  if (!details.specifications) return;

  product.specs = details.specifications.map(spec => ({
    id: spec.id,
    name: spec.name,
    mandatory: spec.mandatory || 0,
    multi: spec.multi || 0,
    options: (spec.values || []).map(val => ({
      id: val.id,
      name: val.name,
      price: safeParseFloat(val.price),
      checked: val.checked === 1,
      exclusives: val.exclusives || []
    }))
  }));
}

// 解析奈雪规格
function parseNaixueSpecs(details) {
  if (!details.spu_specs) return;

  product.specs = details.spu_specs.map(spec => ({
    id: spec.code,
    name: spec.name,
    options: (spec.values || []).map(val => ({
      id: val.code,
      name: val.name,
      price: safeParseFloat(val.price),
      checked: val.checked === 1
    }))
  }));

  product.accessories = details.accessories || [];
  product.skuList = details.sku_infos || [];
}

// 解析星巴克/麦当劳规格（结构相似）
function parseOptionalSpecs(details) {
  product.requiredProducts = details.required || [];

  if (details.optional) {
    product.specs = details.optional.map(opt => ({
      id: opt.id,
      name: opt.name,
      options: (opt.sku_infos || []).map(sku => ({
        id: sku.id,
        name: sku.name,
        price: safeParseFloat(sku.price),
        checked: sku.checked || false,
        enabled: sku.enable !== false && sku.disable !== true,
        img: sku.img
      }))
    }));
  }
}

// 解析星巴克规格
function parseStarbucksSpecs(details) {
  parseOptionalSpecs(details);
}

// 解析麦当劳规格
function parseMcdonaldSpecs(details) {
  parseOptionalSpecs(details);
}

// 解析瑞幸规格
function parseLuckinSpecs(details) {
  if (!details.specifications) return;

  product.specs = details.specifications.map(spec => ({
    name: spec.name,
    options: (spec.ingredients || []).map(ing => ({
      name: ing.name,
      price: safeParseFloat(ing.price),
      checked: ing.checked || false
    }))
  }));

  product.skuList = details.sku_infos || [];
}

// 解析库迪规格
function parseCudiSpecs(details) {
  if (!details.specItems) return;

  product.specs = details.specItems.map(spec => ({
    id: spec.specItemNo,
    name: spec.specItemName,
    options: (spec.specValueList || []).map(val => ({
      id: val.value,
      name: val.name,
      recommendFlag: val.recommendFlag
    }))
  }));

  product.skuList = details.skuCombinList || [];
}

// 通用解析
function parseGenericSpecs(details) {
  const sourceSpecs = details.specs || details.specGroups;
  if (!sourceSpecs) return;

  product.specs = sourceSpecs.map(spec => ({
    name: spec.name || spec.specName,
    options: (spec.options || spec.items || []).map(opt => ({
      name: opt.name || opt.optionName,
      price: safeParseFloat(opt.price || opt.addPrice)
    }))
  }));
}

// ==================== 初始化 ====================
// 初始化默认选中
function initializeDefaultSelection() {
  // 对于需要 SKU 验证的品牌，从第一个有效 SKU 初始化
  if (SKU_VALIDATION_BRANDS.includes(product.brandType) && product.skuList.length > 0) {
    initializeFromValidSKU();
    return;
  }

  // 其他品牌：使用推荐项或第一个选项
  product.specs.forEach(spec => {
    if (!spec.options || spec.options.length === 0) return;

    // 查找默认选中项（已勾选的或第一个）
    const defaultOption = spec.options.find(opt => opt.checked) || spec.options[0];

    selectedSpecs[getSpecKey(spec)] = getOptionKey(defaultOption);
  });

  // 喜茶：处理默认选中的互斥冲突
  if (product.brandType === BRAND_TYPES.HEYTEA) {
    resolveInitialExclusionConflicts();
  }
}

// 从有效的 SKU 初始化默认选择（库迪/奈雪/瑞幸）
function initializeFromValidSKU() {
  // 找到第一个有效的 SKU（优先使用推荐的）
  const firstSku = product.skuList.find(sku => !sku.saleOut && !sku.haltSale) || product.skuList[0];

  if (!firstSku) {
    console.warn('没有找到有效的 SKU');
    return;
  }

  console.log('使用 SKU 初始化默认选择:', firstSku.skuName || firstSku.skuShowName);

  // 从 SKU 的规格中提取默认值
  const skuSpecs = firstSku.skusSpecs || firstSku.specs || [];

  skuSpecs.forEach(skuSpec => {
    const specKey = skuSpec.code || skuSpec.specItemNo || skuSpec.name;
    const optionValue = skuSpec.spec_code || skuSpec.specItemValue || skuSpec.spec_name;

    if (specKey && optionValue) {
      selectedSpecs[specKey] = optionValue;
    }
  });

  console.log('SKU 初始化后的默认选择:', JSON.parse(JSON.stringify(selectedSpecs)));

  // 更新价格（使用 SKU 的价格）
  if (firstSku.salePrice) {
    product.basePrice = safeParseFloat(firstSku.salePrice);
  }
}

// 解决初始化时的互斥冲突（喜茶）
function resolveInitialExclusionConflicts() {
  const conflicts = [];

  // 检查所有已选中的选项，找出互斥冲突
  for (const [specKey, optionKey] of Object.entries(selectedSpecs)) {
    const spec = findSpec(specKey);
    if (!spec) continue;

    const option = findOption(spec, optionKey);
    if (!option?.exclusives?.length) continue;

    // 检查此选项排斥的其他选项
    option.exclusives.forEach(exclusive => {
      const excludedSpecKey = exclusive.id;
      const currentSelected = selectedSpecs[excludedSpecKey];

      if (currentSelected && exclusive.values.some(v => String(v.id) === String(currentSelected))) {
        conflicts.push({ spec: excludedSpecKey, option: currentSelected });
        console.warn('检测到默认选中的互斥冲突:', {
          selected: option.name,
          conflictWith: exclusive
        });
      }
    });
  }

  // 移除冲突的选项
  conflicts.forEach(conflict => {
    delete selectedSpecs[conflict.spec];
    console.log('自动取消冲突选项:', conflict);
  });
}

// ==================== 选项状态判断 ====================
// 判断选项是否被选中
function isOptionSelected(spec, option) {
  return selectedSpecs[getSpecKey(spec)] === getOptionKey(option);
}

// 判断选项是否被禁用
function isOptionDisabled(spec, option) {
  // 1. 麦当劳/星巴克：检查 enabled 字段
  if (option.enabled === false) return true;

  // 2. 喜茶：检查互斥规则
  if (product.brandType === BRAND_TYPES.HEYTEA) {
    return isExcluded(spec, option);
  }

  // 3. 库迪/奈雪/瑞幸：检查 SKU 组合有效性
  if (SKU_VALIDATION_BRANDS.includes(product.brandType) && product.skuList.length > 0) {
    return !isValidSKUCombination(spec, option);
  }

  return false;
}

// 检查是否被互斥（喜茶）
function isExcluded(spec, option) {
  const specKey = getSpecKey(spec);
  const optionKey = getOptionKey(option);

  for (const [selectedSpecKey, selectedOptionKey] of Object.entries(selectedSpecs)) {
    const selectedSpec = findSpec(selectedSpecKey);
    if (!selectedSpec) continue;

    const selectedOption = findOption(selectedSpec, selectedOptionKey);
    if (!selectedOption?.exclusives) continue;

    // 检查当前选项是否在已选选项的互斥列表中
    const isExcluded = selectedOption.exclusives.some(exc =>
        String(exc.id) === String(specKey) &&
        exc.values.some(v => String(v.id) === String(optionKey))
    );

    if (isExcluded) return true;
  }
  return false;
}

// 检查SKU组合是否有效（库迪/奈雪/瑞幸）
function isValidSKUCombination(targetSpec, targetOption) {
  // 模拟选中该选项后的完整选择
  const tempSelection = {
    ...selectedSpecs,
    [getSpecKey(targetSpec)]: getOptionKey(targetOption)
  };

  // 在SKU列表中查找是否存在匹配的组合
  return product.skuList.some(sku => {
    const specs = sku.skusSpecs || sku.specs || [];
    // SKU的每个规格都要能在临时选择中找到匹配
    return specs.every(spec => {
      const key = spec.code || spec.specItemNo || spec.name;
      const value = spec.spec_code || spec.specItemValue || spec.spec_name;
      return !key || tempSelection[key] === value;
    });
  });
}

// ==================== 用户交互 ====================
// 选择规格
function selectSpec(spec, option) {
  if (isOptionDisabled(spec, option)) return;

  const specKey = getSpecKey(spec);
  const optionKey = getOptionKey(option);

  // 处理互斥逻辑（喜茶）
  if (option.exclusives?.length > 0) {
    console.log('处理排斥逻辑，当前选项:', option.name, '排斥规则:', option.exclusives);

    option.exclusives.forEach(exclusive => {
      const excludedSpecId = exclusive.id;
      const excludedValues = exclusive.values || [];

      console.log('排斥规格组ID:', excludedSpecId, '排斥选项:', excludedValues);

      // 查找被排斥的规格组
      const excludedSpec = findSpec(excludedSpecId);
      if (!excludedSpec) return;

      const excludedSpecKey = getSpecKey(excludedSpec);
      const currentSelectedOptionKey = selectedSpecs[excludedSpecKey];

      // 检查当前选中的选项是否在排斥列表中
      if (currentSelectedOptionKey && excludedValues.some(v => String(v.id) === String(currentSelectedOptionKey))) {
        console.log('取消选中被排斥的选项:', excludedSpec.name, '选项ID:', currentSelectedOptionKey);
        delete selectedSpecs[excludedSpecKey];
      }
    });
  }

  // 设置当前选中的选项
  selectedSpecs[specKey] = optionKey;
  console.log('当前已选规格:', JSON.parse(JSON.stringify(selectedSpecs)));
}

// 切换加料选择（奈雪）
function toggleAccessory(accessory) {
  const index = selectedAccessories.value.indexOf(accessory.code);
  if (index > -1) {
    selectedAccessories.value.splice(index, 1);
  } else {
    selectedAccessories.value.push(accessory.code);
  }
}

// ==================== 计算属性 ====================
// 计算当前价格
const currentPrice = computed(() => {
  // 库迪/瑞幸：从匹配的 SKU 中获取价格（不支持加价）
  if ([BRAND_TYPES.CUDI, BRAND_TYPES.LUCKIN].includes(product.brandType) && product.skuList.length > 0) {
    const matchedSku = findMatchedSKU();
    if (matchedSku?.salePrice) {
      console.log('【价格计算】使用SKU价格:', matchedSku.salePrice);
      return safeParseFloat(matchedSku.salePrice).toFixed(2);
    }
  }

  // 其他品牌（喜茶/奈雪/星巴克/麦当劳）：基础价格 + 规格加价
  let finalPrice = product.basePrice;

  // 1. 累加规格选项的加价
  product.specs.forEach(spec => {
    const specKey = getSpecKey(spec);
    const selectedOptionKey = selectedSpecs[specKey];
    if (!selectedOptionKey) return;

    const option = findOption(spec, selectedOptionKey);
    if (option?.price) {
      console.log('【价格计算】规格加价:', spec.name, option.name, '+', option.price);
      finalPrice += option.price;
    }
  });

  // 2. 累加加料的价格（奈雪）
  if (product.accessories.length > 0) {
    selectedAccessories.value.forEach(code => {
      const accessory = product.accessories.find(a => a.code === code);
      if (accessory?.price) {
        console.log('【价格计算】加料加价:', accessory.name, '+', accessory.price);
        finalPrice += accessory.price;
      }
    });
  }

  console.log('【价格计算】最终价格:', finalPrice.toFixed(2));
  return finalPrice.toFixed(2);
});

// 查找匹配当前选择的 SKU（库迪/奈雪/瑞幸）
function findMatchedSKU() {
  return product.skuList.find(sku => {
    const skuSpecs = sku.skusSpecs || sku.specs || [];
    // 检查 SKU 的所有规格是否都与当前选择匹配
    return skuSpecs.every(skuSpec => {
      const key = skuSpec.code || skuSpec.specItemNo || skuSpec.name;
      const value = skuSpec.spec_code || skuSpec.specItemValue || skuSpec.spec_name;
      return selectedSpecs[key] === value;
    });
  });
}

// ==================== 购物车操作 ====================
// 加入购物车
function addToCart() {
  // 1. 验证必选项
  const missingRequired = product.specs.some(spec => {
    return spec.mandatory === 1 && !selectedSpecs[getSpecKey(spec)];
  });

  if (missingRequired) {
    uni.showToast({ title: '请选择必选规格', icon: 'none' });
    return;
  }

  // 2. 构建规格文本（用于显示）
  const specsText = product.specs
      .map(spec => {
        const option = findOption(spec, selectedSpecs[getSpecKey(spec)]);
        return option?.name;
      })
      .filter(Boolean)
      .join('/');

  // 3. 构建购物车项
  const cartItem = {
    id: product.id,
    name: product.name,
    image: product.image,
    price: parseFloat(currentPrice.value),
    selectedSpecs: { ...selectedSpecs },
    selectedAccessories: [...selectedAccessories.value],
    specsText,
  };

  // 4. 添加到购物车
  cateringStore.addToCart(cartItem);

  // 5. 显示成功提示并返回
  uni.showToast({
    title: '已加入购物车',
    icon: 'success'
  });

  setTimeout(() => sheep.$router.back(), 1000);
}
</script>

<style lang="scss" scoped>
.detail-container {
  display: flex;
  flex-direction: column;
  height: 100%;
  background-color: #f5f5f5;
}

.content-scroll {
  flex: 1;
}

.product-main-image {
  width: 100%;
}

.product-info-card,
.spec-card,
.included-products {
  background-color: #fff;
  border-radius: 20rpx;
  margin: 20rpx;
  padding: 30rpx;
}

.product-name {
  font-size: 40rpx;
  font-weight: bold;
}

.product-desc {
  font-size: 26rpx;
  color: #999;
  margin-top: 10rpx;
  line-height: 1.6;
}

.product-price {
  font-size: 44rpx;
  color: #c7000b;
  font-weight: bold;
  margin-top: 20rpx;
}

.spec-group {
  margin-bottom: 40rpx;
  &:last-child {
    margin-bottom: 0;
  }

  .spec-group-header {
    margin-bottom: 20rpx;
  }

  .spec-group-name {
    font-size: 28rpx;
    font-weight: bold;

    .spec-required {
      color: #c7000b;
      margin-left: 8rpx;
      font-size: 24rpx;
    }
  }

  .spec-options {
    display: flex;
    flex-wrap: wrap;
    gap: 20rpx;

    .spec-option {
      background: #f5f5f5;
      color: #333;
      border: 1rpx solid #f5f5f5;
      border-radius: 10rpx;
      padding: 15rpx 30rpx;
      font-size: 26rpx;
      line-height: 1;
      min-width: 120rpx;
      display: flex;
      flex-direction: column;
      align-items: center;
      gap: 8rpx;

      .option-name {
        font-size: 26rpx;
      }

      .option-price {
        font-size: 22rpx;
        color: #c7000b;
      }

      &.active {
        background: #ffebee;
        color: #c7000b;
        border: 1rpx solid #c7000b;
      }

      &.disabled {
        background: #f0f0f0;
        color: #ccc;
        border: 1rpx solid #f0f0f0;

        .option-price {
          color: #ccc;
        }
      }
    }
  }
}

.section-title {
  font-size: 32rpx;
  font-weight: bold;
  margin-bottom: 20rpx;
  color: #333;
}

.included-products {
  .product-item {
    display: flex;
    align-items: center;
    padding: 20rpx 0;
    border-bottom: 1rpx solid #f0f0f0;

    &:last-child {
      border-bottom: none;
    }

    .product-item-img {
      width: 100rpx;
      height: 100rpx;
      border-radius: 10rpx;
      margin-right: 20rpx;
      flex-shrink: 0;
    }

    .product-item-info {
      flex: 1;
      display: flex;
      flex-direction: column;

      .product-item-name {
        font-size: 28rpx;
        color: #333;
        margin-bottom: 8rpx;
      }

      .product-item-amount {
        font-size: 24rpx;
        color: #999;
      }
    }
  }
}

.bottom-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: 120rpx;
  background-color: #fff;
  border-top: 1rpx solid #f0f0f0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 30rpx;
  padding-bottom: constant(safe-area-inset-bottom);
  padding-bottom: env(safe-area-inset-bottom);
  z-index: 100;

  .price-section {
    color: #c7000b;
    font-weight: bold;
    font-size: 28rpx;
    .price-value {
      font-size: 44rpx;
    }
  }

  .add-to-cart-btn {
    background-color: #c7000b;
    color: #fff;
    font-size: 32rpx;
    border-radius: 40rpx;
    padding: 20rpx 80rpx;
    line-height: 1;
  }
}
</style>

